package com.timemanage.dao

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.timemanage.entity.User
import com.timemanage.entity.Work

@Database(version = 1, entities = [User::class, Work::class], exportSchema = false)
abstract class AppDatabase: RoomDatabase() {

    abstract fun userDao():UserDao
    abstract fun WorkDao():WorkDao

    companion object {
        private var instance: AppDatabase? = null
        @Synchronized
        fun getDatabase(context: Context): AppDatabase {
            instance?.let {
                return it
            }
            return Room.databaseBuilder(context.applicationContext,
                AppDatabase::class.java, "app_database")
                .allowMainThreadQueries().build().apply {
                    instance = this
                }
        }
    }
}